<template>
	<view class="activity">
		<top-header :value="2"></top-header>
		<view class="activity_region">
			<view class="nav">
				<view class="item" @click="latest">
					<i class="_new ico"></i>
					<view class="text">最新</view>
				</view>
				<view class="item" @click="apply">
					<i class="_flag1 ico"></i>
					<view class="text">报名中</view>
				</view>
				<view class="item" @click="progress">
					<i class="_flag2 ico"></i>
					<view class="text">进行中</view>
				</view>
				<view class="item" @click="end">
					<i class="_flag3 ico"></i>
					<view class="text">已结束</view>
				</view>
			</view>
			<view class="list">
				<view :id="item.id" v-for="(item,index) in acivityList" :key="index" class="item">
					<view class="content" @click="toDetail(item)">
						<view class="title">{{item.activeName}}</view>
						<image :src="item.imgUrl" mode="" class="poster"></image>
						<view class="desc">{{item.activeStatus}}</view>
						<view class="arrow_region">
							<view class="left">不限</view>
							<view class="right"><view class="btn" :style="{'background-color':item.bgcolor}">{{item.activeStatusCode}}</view></view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<tabbar></tabbar>
	</view>
</template>

<script>
export default {
	data() {
		return {
			acivityList:[],
			acivityList1:[],
			acivityList2:[],
			acivityList3:[],
			bgcolor:'',
		};
	},
	onLoad() {
		this.getAcivity()
	},
	methods:{
		latest(){
			this.getAcivity()
		},
		apply(){
			let acivityList1 = this.acivityList1.filter((item) => {
				return item.activeStatus == '报名中'
			})
			this.acivityList = acivityList1
		},
		progress(){
			let acivityList2 = this.acivityList2.filter((item) => {
				return item.activeStatusCode == '进行中'
			})
			this.acivityList = acivityList2
		},
		end(){
			let acivityList3 = this.acivityList3.filter((item) => {
				return item.activeStatus == '报名结束'
			})
			this.acivityList = acivityList3
		},
		toDetail(item){
			// let id = event.currentTarget.id
			// uni.navigateTo({
			// 	url:"/pages/activityDetail/activityDetail?id="+id
			// })
			console.log(item);
			this.$store.state.active = JSON.parse(JSON.stringify(item));
			uni.navigateTo({
				url: "/pages/activityDetail/activityDetail"
			})
		},
		async getAcivity(){
			let res = await this.request({
				url:'/active',
				method:'GET'
			})
			console.log(res);
			this.acivityList = res.data
			this.acivityList1 = res.data
			this.acivityList2 = res.data
			this.acivityList3 = res.data
			
			for(let i = 0;i < this.acivityList.length;i++){
				let endTime = this.acivityList[i].endTime.replace('T'," ")
				let sigendTime = new Date(Date.parse(endTime.replace(/-/g,"/")));
				let curDate = new Date()
				if(curDate >= sigendTime){
					this.acivityList[i].activeStatus = '报名结束'
					this.acivityList[i].activeStatusCode = '圆满结束'
					this.acivityList[i].statusCode = ''
					this.acivityList[i].bgcolor = '#aaa'
				}else {
					this.acivityList[i].activeStatus = '报名中'
					this.acivityList[i].activeStatusCode = '进行中'
					this.acivityList[i].statusCode = 1
					this.acivityList[i].bgcolor = '#ff589b'
				}
			}
			for(let i = 0;i < this.acivityList1.length;i++){
				let endTime = this.acivityList1[i].endTime.replace('T'," ")
				let sigendTime = new Date(Date.parse(endTime.replace(/-/g,"/")));
				let curDate = new Date()
				if(curDate >= sigendTime){
					this.acivityList1[i].activeStatus = '报名结束'
					this.acivityList1[i].activeStatusCode = '圆满结束'
					this.acivityList1[i].bgcolor = '#aaa'
				}else {
					this.acivityList1[i].activeStatus = '报名中'
					this.acivityList1[i].activeStatusCode = '进行中'
					this.acivityList1[i].bgcolor = '#ff589b'
				}
			}
			for(let i = 0;i < this.acivityList2.length;i++){
				let endTime = this.acivityList2[i].endTime.replace('T'," ")
				let sigendTime = new Date(Date.parse(endTime.replace(/-/g,"/")));
				let curDate = new Date()
				if(curDate >= sigendTime){
					this.acivityList2[i].activeStatus = '报名结束'
					this.acivityList2[i].activeStatusCode = '圆满结束'
					this.acivityList2[i].bgcolor = '#aaa'
				}else {
					this.acivityList2[i].activeStatus = '报名中'
					this.acivityList2[i].activeStatusCode = '进行中'
					this.acivityList2[i].bgcolor = '#ff589b'
				}
			}
			for(let i = 0;i < this.acivityList3.length;i++){
				let endTime = this.acivityList3[i].endTime.replace('T'," ")
				let sigendTime = new Date(Date.parse(endTime.replace(/-/g,"/")));
				let curDate = new Date()
				if(curDate >= sigendTime){
					this.acivityList3[i].activeStatus = '报名结束'
					this.acivityList3[i].activeStatusCode = '圆满结束'
					this.acivityList3[i].bgcolor = '#aaa'
				}else {
					this.acivityList3[i].activeStatus = '报名中'
					this.acivityList3[i].activeStatusCode = '进行中'
					this.acivityList3[i].bgcolor = '#ff589b'
				}
			}
			
		},
	}
};
</script>

<style lang="scss">
.activity {
	padding: 120rpx 0 104rpx;
	.activity_region {
		padding: 0 24rpx;
		box-sizing: border-box;
		.nav {
			display: flex;
			width: 100%;
			padding: 20rpx 0;
			box-sizing: border-box;
			background-color: #fff;
			border-radius: 20rpx;
			.item {
				width: 25%;
				display: flex;
				flex-flow: column;
				align-items: center;
				justify-content: center;
				.ico {
					width: 80rpx;
					height: 80rpx;
					border-radius: 50%;
					display: flex;
					justify-content: center;
					align-items: center;
					color: #fff;
					font-size: 40rpx;
				}
				.text {
					margin-top: 10rpx;
					font-size: 28rpx;
				}
				._new {
					background-color: #d88cff;
					background-image: -webkit-linear-gradient(135deg, #c05cf4, #ecc6ff);
					text-shadow: 0rpx 2rpx 2rpx #b150e3;
				}

				._flag1 {
					background-color: #0096ff;
					background-image: -webkit-linear-gradient(135deg, #0096ff, #63caff);
					text-shadow: 0rpx 2rpx 2rpx #057ed2;
				}

				._flag2 {
					background-color: #ff8800;
					background-image: -webkit-linear-gradient(135deg, #ff8800, #ffb662);
					text-shadow: 0rpx 2rpx 2rpx #fd7100;
				}

				._flag3 {
					background-color: #43c38b;
					background-image: -webkit-linear-gradient(135deg, #43c38b, #8addb9);
					text-shadow: 0rpx 2rpx 2rpx #1ba368;
				}
			}
		}
		.list{
			margin-top: 20rpx;
			.item{
				margin-top: 20rpx;
				background-color: #fff;
				border-radius: 20rpx;
				width: 100%;
				padding: 40rpx 30rpx;
				box-sizing: border-box;
				.title{
					
				}
				.poster{
					width: 646rpx;
					height: 300rpx;
					border-radius: 10rpx;
					margin-top: 30rpx;
				}
				.desc{
					font-size: 24rpx;
					margin-top: 30rpx;
				}
				.arrow_region{
					display: flex;
					justify-content: space-between;
					align-items: center;
					font-size: 28rpx;
					margin-top: 30rpx;
					.right{
						.btn{
							padding: 10rpx;
							color: #fff;
							border-radius: 10rpx;
							background-color: #aaa;
							font-size: 28rpx;
						}
					}
				}
			}
		}
	}
}
</style>
